ZErr
Custom JS error creator that subclasses Error
, sets .name
.stack
and .message
, and provides simple interpolation to construct error messages.
var zerr = require('zerr')
var BadParam = zerr('BadParam', '% must be a %')
try { throw new BadParam('foo', 'string') }
catch (e) {
console.log(e.name)
console.log(e.message)
console.log(e.stack)
console.log(e instanceof Error)
console.log(e instanceof BadParam)
}
throw BadParam('foo', 'string')
var BadParam = zerr('BadParam')
try { throw new BadParam('foo is bad') }
catch (e) {
console.log(e.message)
}
try { throw new BadParam(new BadParam('earlier foo was bad'), 'foo is bad') }
catch (e) {
console.log(e.stack)
}